package com.sxz.sbs.widget;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.sxz.sbs.R;

import java.util.ArrayList;
import java.util.List;

/**
 * 多个手机号
 */

public class MultiplePhoneDialog extends Dialog{
    private Context context;
    private MultiplePhoneAdapter adapter;
    private List<String> phone = new ArrayList<>();
    private OnChosePhoneListener onChosePhoneListener;

    public void setOnChosePhoneListener(OnChosePhoneListener onChosePhoneListener) {
        this.onChosePhoneListener = onChosePhoneListener;
    }

    public MultiplePhoneDialog(Context context, List<String> phone) {
        super(context, R.style.Theme_Dialog_From_Bottom);
        this.context = context;
        this.phone = phone;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.multiple_phone_layout);
        RecyclerView recyclerView = findViewById(R.id.recyclerView_phone);
        recyclerView.setLayoutManager(new LinearLayoutManager(context));
        recyclerView.addItemDecoration(new DividerItemDecoration(context,DividerItemDecoration.VERTICAL));
        adapter = new MultiplePhoneAdapter(phone);
        recyclerView.setAdapter(adapter);
        recyclerView.addOnItemTouchListener(new OnItemClickListener() {
            @Override
            public void onSimpleItemClick(BaseQuickAdapter adapter, View view, int position) {
                dismiss();
                if (onChosePhoneListener != null) {
                    onChosePhoneListener.onSelectPhone(phone.get(position));
                }
            }
        });
    }
    public class MultiplePhoneAdapter extends BaseQuickAdapter<String,BaseViewHolder> {

        public MultiplePhoneAdapter(@Nullable List<String> data) {
            super(R.layout.item_multiple_phone_layout,data);
        }

        @Override
        protected void convert(BaseViewHolder helper, String item) {
            helper.setText(R.id.tv_multiple_phone,item);
        }
    }
    public interface OnChosePhoneListener {
        void onSelectPhone(String phone);
    }
}
